<template>
  <a-modal
    title="审批"
    width="40%"
    :visible="visible"
    :confirmLoading="loading"
    destroyOnClose
    @ok="handleSubmit"
    @cancel="visible = false"
  >
    <a-spin :spinning="loading">
      <a-form-model ref="form" :model="entity" :rules="rules" v-bind="layout">
        <a-form-model-item label="审批状态" prop="ApprovalStatus">
          <a-radio-group button-style="solid" v-model="entity.ApprovalStatus">
            <a-radio-button :value="1">
              通过
            </a-radio-button>
            <a-radio-button :value="2">
              驳回
            </a-radio-button>
          </a-radio-group>
        </a-form-model-item>
        <a-form-model-item label="审核日期">
          <a-date-picker format="YYYY-MM-DD" style="width: 100%" v-model="entity.ApprovalDate" />
        </a-form-model-item>
        <a-form-model-item label="审批意见" prop="ApprovalComments">
          <a-textarea v-model="entity.ApprovalComments" autocomplete="off" />
        </a-form-model-item>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
import moment from 'moment'
export default {
  props: {
    parentObj: Object
  },
  data() {
    return {
      loading: false,
      imageUrl: '',
      headers: '',
      id: '',
      layout: {
        labelCol: { span: 5 },
        wrapperCol: { span: 18 }
      },
      visible: false,

      entity: {
        ApprovalDate: moment(new Date()),
        ApprovalStatus: 1,
        ApprovalComments: ''
      },
      rules: {},
      title: ''
    }
  },
  methods: {
    openForm(id) {
      this.visible = true
      this.id = id
      this.entity = { ApprovalDate: moment(new Date()), ApprovalStatus: 1, ApprovalComments: '' }
      // this.entity.
    },

    handleSubmit() {
      var searchArr = [
        {
          Condition: 'ApprovalComments',
          Keyword: this.entity.ApprovalComments
        },
        {
          Condition: 'ApprovalDate',
          Keyword: this.entity.ApprovalDate
        },
        {
          Condition: 'ApprovalStatus',
          Keyword: this.entity.ApprovalStatus
        }
      ]

      this.$http
        .post('/SampleManagement/SPL_SampleApplyMain/UpdateDataByCondition', {
          Conditions: searchArr,
          ids: [this.id]
        })
        .then(resJson => {
          if (resJson.Success) {
            this.$message.success('操作成功!')
            this.visible = false

            this.parentObj.getDataList()
          } else {
            this.$message.error(resJson.Msg)
          }
        })
    },
    init() {
      this.visible = true
      this.entity = {}
      this.$nextTick(() => {
        this.$refs['form'].clearValidate()
      })
    }
  }
}
</script>
<style>
.ant-upload {
  text-align: center !important;
}
.avatar-uploader > .ant-upload {
  width: 128px;
  height: 128px;
}
.ant-upload-select-picture-card i {
  font-size: 32px;
  color: #999;
}

.ant-upload-select-picture-card .ant-upload-text {
  margin-top: 8px;
  color: #666;
}
</style>
